import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    // 重定向
    {path:'/',redirect:'/profile'},
    {path:'/profile',component:()=>import("@/views/ProfileEdit.vue"),meta:{title:'个人中心'}},
    {path:'/address',component:()=>import("@/views/AddressManager.vue"),meta:{title:'收获地址管理'}},
    {path:'/address/edit/:id?',component:()=>import("@/views/AddressEdit.vue"),meta:{title:'地址添加/编辑页'}},
    {path:'/account',component:()=>import("@/views/AccountView.vue"),meta:{title:'账号安全'}}
  ]
})
// 全局前置守卫（刚进入就执行）
// router.beforeEach((to,from,next)=>{
router.beforeEach((to)=>{
  document.title = to.meta.title as string
})
// 全局后置守卫（完全进入网页后才会执行回调）--正常都放在后置守卫中
// router.afterEach((to)=>{
//   document.title = to.meta.title as string
// })
export default router
